package com.goambu.driver.autenticacion.controller;

import org.apache.http.HttpResponse;

import com.goambu.driver.autenticacion.entities.DestinyResponse;
import com.goambu.driver.autenticacion.entities.GeocoderResponse;
import com.goambu.driver.framework.controller.internet.Controller;
import com.goambu.driver.framework.controller.internet.HttpConnector;
import com.google.gson.Gson;

public class MyGeocoderController extends Controller  {
	public static MyGeocoderController instance = null;
	public String currentAddress = "";
	
	public static MyGeocoderController getInstance() {
		if (instance == null) {
			instance = new MyGeocoderController();
		}
		return instance;
	}
	
	public static GeocoderResponse getFromLocation (String path){
		Gson gs = new Gson();
		String strResponse = "";
		GeocoderResponse objResponse = null;
		HttpResponse respuesta = null;
		
		if (HttpConnector.isNetworkAvailable()){
			try{
				strResponse = getStringFromPOST(path, null);
				
			}
			catch(Exception e){
				e.printStackTrace();
			}
			
			if (!strResponse.isEmpty()) {
				objResponse = gs.fromJson(strResponse, GeocoderResponse.class);
				if (objResponse.status.equals("ZERO_RESULTS")) return null;
				else return objResponse;
			} else return null;
		}
		return null;
	}
	
	public static DestinyResponse getDestinyInfoFromLocation (String path){
		Gson gs = new Gson();
		String strResponse = "";
		DestinyResponse objResponse = null;
		HttpResponse respuesta = null;
		
		try{
			strResponse = getStringFromPOST(path, null);
			
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		if (!strResponse.isEmpty()) {
			objResponse = gs.fromJson(strResponse, DestinyResponse.class);
			if (objResponse.status.equals("ZERO_RESULTS")) return null;
			else return objResponse;
		} else return null;
	}

}
